package com.wfms.controller;

import com.wfms.bean.User;
import com.wfms.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * Created by Administrator on 2017/12/24.
 */
@RestController
@RequestMapping("/user")
public class FeignController {
    @Autowired
    UserService service;
    @Autowired
    UserServiceNoEureka serviceNoEureka;

    @Autowired
    EurekaServiceAuth eurekaServiceAuth;

    @Autowired
    FeignDefaultHttp defaultHttpService;

    @Autowired
    UserServiceHystrx userServiceHystrx;

        @RequestMapping("/getById")
    public User getById(){
        return service.findById(1);
    }

    @RequestMapping("/save")
    public User save(){
        User user=new User(new Random().nextInt(100)+"zhangsan",11);
        return  service.saveUser(user);
    }


    @GetMapping("/noEureka/getById")
    public User getByNoEurekaId(){
        return serviceNoEureka.findById(1);
    }


    @GetMapping("/getEurekaInfo")
    public  String getEurekaInfo(){
        final  String  serviceName="EUREKACLIENT";
        return eurekaServiceAuth.getEurekaServiceByName(serviceName);
    }

    @GetMapping("/getDefaultFeign")
    public User getDefaultFeign(){
        return defaultHttpService.findById(1);
    }


    @GetMapping("/getDefautErrorWithHystrx")
    public User getDefautErrorWithHystrx(){
        return userServiceHystrx.findById(1);
    }

}
